<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<canvas id="canvas" style="border: 1px solid red;"></canvas>
		<br>
		<input type="button" id="btn" value="移动" />
		<script type="text/javascript">
			var canvas = document.getElementById("canvas")
			var cxt = canvas.getContext('2d')

			//案例1
			// cxt.fillStyle="aqua"
			// cxt.fillRect(30,30,50,50);
			// cxt.translate(50,50)
			// cxt.fillRect(30,30,50,50);

			//案例2
			cxt.fillStyle = "aqua"
			cxt.fillRect(30, 30, 50, 50);
			var move_btn = document.getElementById("btn")
			move_btn.onclick = function() {
				cxt.clearRect(0, 0, canvas.width, canvas.height)
				cxt.translate(10, 10)
				cxt.fillRect(30, 30, 50, 50);
			}
		</script>
	</body>
</html>
